<template>
  <div class="aside">
    <el-menu
      active-text-color="rgb(64, 158, 255)"
      background-color="rgb(48, 65, 86)"
      class="el-menu-vertical-demo"
      :default-active="route.path"
      text-color="#fff"
      :collapse="isCollapse"
      router
      unique-opened
    >
      <el-menu-item index="/index">
        <i class="iconfont homepage"></i>
        <span>首页</span>
      </el-menu-item>
      <el-sub-menu :index="'/' + sub.name" v-for="sub in menus" :key="sub.id">
        <template #title>
          <i class="iconfont" :class="sub.icon"></i>
          <span>{{ sub.title }}</span>
        </template>
        <template v-for="ele in sub.children" :key="ele.id">
          <el-menu-item
            :index="'/' + sub.name + '/' + ele.name"
            v-if="ele.hidden === 0"
          >
            <i class="iconfont" :class="ele.icon"></i>
            {{ ele.title }}
          </el-menu-item>
        </template>
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { inject, ref } from "vue";
import { useUserStore } from "@/store/user";
import { useRoute } from "vue-router";
//控制左侧菜单显示隐藏
const isCollapse = inject("isCollapse");

//用户信息
const userStore = useUserStore();
//菜单信息
const menus = userStore.routes;
//路径
const route = useRoute();
</script>

<style scoped lang="less">
.aside {
  .el-menu-vertical-demo {
    width: 250px;
    border-right: 1px solid rgb(48, 65, 86);
  }
  :deep(.el-menu--collapse) {
    width: 64px;
  }
}
</style>
